home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ear / mui23dev.lha / MUI / Developer / Modula / Demo / ComboBox.mod < prev    next >
Text File  |  1994-06-04  |  14KB  |  370 lines

  1. MODULE ComboBox;
  2. (*$ LargeVars:=FALSE *)
  3.  
  4. (* $VER: ComboBox 1.002 (17 Oct 1993)
  5. **
  6. **
  7. ** This little Prog. will create a ComboBox as used in Windoze,
  8. ** but ofcourse better, because it's MUI :-)
  9. **
  10. ** $HISTORY:
  11. **
  12. ** 17 Oct 1993 : 001.002 :  some little enhancements
  13. ** 17 Oct 1993 : 001.001 :  created
  14. **
  15. **
  16. *)
  17.  
  18.  
  19. (***/ "IMPORTS" /***)
  20. IMPORT  MD:MuiD;
  21. IMPORT  ML:MuiL;
  22. IMPORT  MM:MuiMacros;
  23. FROM    MuiMacros   IMPORT NoteButton, NoteClose, Child, set, get,
  24.                            STRING, STRPTR, STRARR, STRARRPTR,
  25.                            MakeHook, MakeID, AddMember, RemMember;
  26. FROM    MuiSupport  IMPORT fail, APTR, DoMethod, DOMethod;
  27. FROM    UtilityD    IMPORT HookPtr, tagEnd;
  28. FROM    IntuitionD  IMPORT WindowPtr;
  29. FROM    ExecL       IMPORT Wait;
  30. FROM    SYSTEM      IMPORT TAG, ADR, LONGSET, CAST;
  31. (******)
  32. (***/ "TYPE" /***)
  33. TYPE   ComboArr         = ARRAY[0..9] OF STRPTR;   (* C-Array of strings *)
  34.        tagbuffer        = ARRAY[0..30] OF LONGINT; (* buffer for the tags *)
  35. (******)
  36. (***/ "CONST" /***)
  37. CONST   True    = 1;    (* for the get routine of MuiMacros, because it *)
  38.         False   = 0;    (* excepts just LONGINT and no BOOLEAN values *)
  39.  
  40.         IDOK            = 1;       (* for the notifies *)
  41.         IDCancel        = 2;
  42.         IDPopUp         = 3;
  43.         IDPopOk         = 4;
  44.         IDPopCancel     = 5;
  45.         IDPopDouble     = 6;
  46.  
  47.  
  48.         (* The contents for our Combo-List *)
  49.  
  50.         ComboArray      = ComboArr{ADR("Amiga 500"),
  51.                                    ADR("Amiga 600"),                                   ADR("Amiga 1000"),
  52.                                    ADR("Amiga 1200"),
  53.                                    ADR("Amiga 2000"),
  54.                                    ADR("Amiga 3000"),
  55.                                    ADR("Amiga 4000"),
  56.                                    ADR("Amiga 4000T"),
  57.                                    ADR("Amiga 5000 :-)"),
  58.                                    NIL};
  59.  
  60. (******)
  61. (***/ "VAR" /***)
  62. VAR
  63.     app, window,
  64.     OKBut, CancelBut,
  65.     String, StringGroup,
  66.     Label, Popup, image       : APTR;          (* for objects *)
  67.     signals                   : LONGSET;
  68.     msg                       : LONGINT;
  69.     running                   :=BOOLEAN{TRUE};
  70.     buffer, buffer1, buffer2  : tagbuffer;     (* for tags *)
  71.     PopUpHook                 : HookPtr;
  72.     ListEntry                 : STRPTR;        (* for the actual entry 
  73.                                                   in our Popup-Listview
  74.                                                   This must be global,
  75.                                                   because otherwise
  76.                                                   it gets destroyed
  77.                                                   when the hook
  78.                                                   exits
  79.                                                *)
  80. (******)
  81. (***/ "PopUpFunc" /***)
  82. (* So here is the hook function for the PopUp-Object *)
  83.  
  84. PROCEDURE PopUpFunc (hook : HookPtr;
  85.                      obj  : APTR;
  86.                      args : APTR) : APTR;
  87.  
  88. VAR
  89.     Popupwindow,
  90.     PopupOKBut,
  91.     PopupCancelBut,
  92.     PopupList,
  93.     PopupListview             : APTR;       (* for the objects *)
  94.     left, top                 : LONGINT;    (* to calculate our window- *)
  95.     width, height             : LONGINT;    (* position                 *)
  96.     win                       : WindowPtr;  (*        - dito -          *)
  97.     buffer                    : tagbuffer;  (* don't forget this!!!! use NOT the global one *)
  98.     window                    : APTR;       (* the window, where the popup-obj
  99.                                                resides in *)
  100.     app                       : APTR;       (* dito for the app-object *)
  101.  
  102.     
  103.     BEGIN
  104.  
  105.  
  106.      (* 
  107.         first of all get the window and application-objects of the
  108.         popup-object, so that we do not need global vars
  109.      *)
  110.  
  111.         get(obj, MD.maWindowObject,      ADR(window));
  112.         get(obj, MD.maApplicationObject, ADR(app));
  113.  
  114.  
  115.      (* 
  116.         Now generate the objects and add it to the application
  117.         by an omADDMEMBER-Call
  118.      *)
  119.  
  120.      (* the buttons for the Popup-Object *)
  121.         PopupOKBut      := MM.Keybutton ("OK",'o');
  122.         PopupCancelBut  := MM.Keybutton ("Cancel",'c');
  123.  
  124.         (* Now the list for the Popup-Object
  125.            We do not need a Construct, Destruct or Display-Hook,
  126.            because we have a constant array of strings, so they
  127.            do not need be copied.
  128.            We also have simple strings, so that we have not to
  129.            supply a display hook! 
  130.         *)
  131.         PopupList       := MM.ListObject(TAG(buffer,
  132.                                 MD.maFrame,            MD.mvFrameInputList,
  133.                                 tagEnd));
  134.  
  135.         PopupListview   := MM.ListviewObject(TAG(buffer,
  136.                                 MD.maListviewList,     PopupList,
  137.                                 tagEnd));
  138.  
  139.      (* get position and dimension of the popup-object *)
  140.         get(obj, MD.maHeight,         ADR(height));
  141.         get(obj, MD.maTopEdge,        ADR(top));
  142.         get(obj, MD.maLeftEdge,       ADR(left));
  143.         get(obj, MD.maWindow,         ADR(win));
  144.         get(obj, MD.maWidth,          ADR(width));
  145.  
  146.      (* create window under the Popup-Object *)
  147.         Popupwindow     := MM.WindowObject(TAG(buffer,
  148.                                 MD.maWindowTitle,      ADR("Select computer"),
  149.                                 MD.maWindowLeftEdge,   win^.leftEdge+left,
  150.                                 MD.maWindowTopEdge,    win^.topEdge+height+top,
  151.                                 MD.maWindowWidth,      width,
  152.                                 MD.maWindowDragBar,    FALSE, (* no dragging *)
  153.                                 MD.maWindowCloseGadget,FALSE, (* no closing  *)
  154.                                 MD.maWindowNoMenus,    TRUE,
  155.                                 
  156.                                 MM.WindowContents,
  157.                                         MM.VGroup(TAG(buffer1,
  158.                                             Child,     PopupListview,
  159.                                             Child,     MM.HGroup(TAG(buffer2,
  160.                                                           Child,   PopupOKBut,
  161.                                                           Child,   PopupCancelBut,
  162.                                                           tagEnd)),
  163.                                             tagEnd)),
  164.                                         tagEnd));
  165.  
  166.      (* Notify *)
  167.         NoteButton(app, PopupOKBut,     IDPopOk);
  168.         NoteButton(app, PopupCancelBut, IDPopCancel);
  169.         NoteClose(app, Popupwindow,     IDPopCancel);
  170.      (* IF someone doubleclicks on the list, send IDPopDouble *)
  171.         DoMethod(PopupListview, TAG(buffer, MD.mmNotify,
  172.             MD.maListviewDoubleClick, TRUE,
  173.             app, 2,
  174.             MD.mmApplicationReturnID, IDPopDouble));
  175.  
  176.      (* set up the cycle chain *)
  177.         DoMethod(Popupwindow, TAG(buffer, MD.mmWindowSetCycleChain,
  178.                     PopupOKBut,
  179.                     PopupCancelBut,
  180.                     PopupListview,
  181.                     NIL));
  182.  
  183.      (* make the listview the default active object *)
  184.         set(Popupwindow, MD.maWindowDefaultObject, PopupListview);
  185.  
  186.      (* Insert things in list *)
  187.         DoMethod(PopupList, TAG(buffer, MD.mmListInsert,
  188.                 ADR(ComboArray), -1, MD.mvListInsertBottom));
  189.         
  190.      (* add window to application *)
  191.         AddMember(app,Popupwindow);
  192.  
  193.      (* open window *)
  194.         set(Popupwindow,MD.maWindowOpen,True);
  195.         set(window, MD.maWindowSleep, True);
  196.  
  197.      (* MAIN LOOP *)
  198.  
  199.         WHILE running DO
  200.             (* wait for signals IF necessary *)
  201.             IF signals <> LONGSET{} THEN signals:=Wait(signals); END;
  202.  
  203.             (* get the message *)
  204.             msg:=DOMethod(app,TAG(buffer,
  205.                                 MD.mmApplicationInput,ADR(signals)));
  206.  
  207.             CASE msg OF
  208.             | MD.mvApplicationReturnIDQuit :  (* quit!
  209.                                                  this is easy here, because
  210.                                                  we have access to the
  211.                                                  running-Var 
  212.                                                  otherwise you perhaps
  213.                                                  can provide a callback-hook
  214.                                                  for the quit-signal
  215.                                               *)
  216.                     running:=FALSE;
  217.                     RETURN 0;
  218.  
  219.             | IDPopCancel :     (* Close window *)
  220.  
  221.                     set(Popupwindow, MD.maWindowOpen, False);
  222.                     set(window, MD.maWindowSleep, False);
  223.                     RETURN 0;
  224.  
  225.             | IDPopOk, IDPopDouble :
  226.  
  227.                  (*
  228.                     now we have to put the actual listentry
  229.                     in the stringgadget
  230.                  *)
  231.  
  232.                  (* copy the selected item into the string gadget *)
  233.                     DoMethod(PopupList, TAG(buffer, MD.mmListGetEntry,
  234.                         MD.mvListGetEntryActive, ADR(ListEntry)));
  235.  
  236.                     IF ListEntry#NIL THEN
  237.                         set (obj, MD.maStringContents, ADR(ListEntry^));
  238.                         (* we can use 'obj' instead of 'String' because
  239.                            MUI will give this to all of the childs
  240.                            of the Popup-group! (a group with a string and an 
  241.                            image object)
  242.                         *)
  243.                     END;
  244.                     
  245.                  (* Alternative implementation of copy-process
  246.            
  247.                     get(PopupList, MD.maListActive, ADR(pos));
  248.                     IF pos#MD.mvListActiveOff THEN
  249.                         set(String, MD.maStringContents, ADR(ComboArray[pos]^));
  250.                     END;
  251.                  *)
  252.  
  253.                  (* Close our window and wake up the one with the PopUp-Object *)
  254.                     set(Popupwindow, MD.maWindowOpen, False);
  255.                     set(window, MD.maWindowSleep, False);
  256.  
  257.                     RemMember(app, Popupwindow);
  258.                     ML.mDisposeObject(Popupwindow);   (* DON'T forget ! *)
  259.                     RETURN 0;
  260.             ELSE
  261.             END;
  262.         END; (*WHILE*)
  263.  
  264.     RETURN 0;
  265.     END PopUpFunc;
  266. (******)
  267. (***/ "Main program" /***)
  268. BEGIN
  269.  
  270.  (* define the Popup-Hook *)
  271.     MakeHook(PopUpFunc,PopUpHook);
  272.  
  273.  
  274.  (* Lets do the buttons for the main window *)
  275.     OKBut           := MM.Keybutton ("OK",'o');
  276.     CancelBut       := MM.Keybutton ("Cancel",'c');
  277.  
  278.  
  279.  (* Now the string-gadget *)
  280.     Label           := MM.KeyLabel2("Computer",'m');
  281.     String          := MM.KeyString("Amiga 2000",200,'m');
  282.  
  283.  (* the PopUp-Object *)
  284.     Popup  := MM.Popup(String,PopUpHook,image,MD.miPopUp);
  285.  
  286.  (* now put all in a group *)
  287.     StringGroup     := MM.HGroup(TAG(buffer,
  288.                             Child,         Label,
  289.                             Child,         Popup));
  290.  
  291.  
  292.  (* lets do the window *)
  293.     window          := MM.WindowObject(TAG(buffer,
  294.                             MD.maWindowTitle,       ADR("ComboBoxDemo"),
  295.                             MD.maWindowScreenTitle, ADR("Denn auch der Darm istein FIFO-Speicher!"),
  296.                             MD.maWindowID,          MakeID("COMB"),
  297.                                 MM.WindowContents,
  298.                                     MM.VGroup(TAG(buffer1,
  299.                                             Child,  StringGroup,
  300.                                             Child,  MM.HGroup(TAG(buffer2,
  301.                                                         Child,     OKBut,
  302.                                                         Child,     CancelBut,
  303.                                                         tagEnd)),
  304.                                             tagEnd)),
  305.                                     tagEnd));
  306.  
  307.  (* and at last the application-object *)
  308.  
  309.     app     :=MM.ApplicationObject(TAG(buffer,
  310.                 MD.maApplicationTitle,      ADR("Kochtopf's ComboBox"),
  311.                 MD.maApplicationAuthor,     ADR("Christian Scholz"),
  312.                 MD.maApplicationVersion,    ADR("$VER: ComboBox V1 (16.10.1993)"),
  313.                 MD.maApplicationCopyright,  ADR("© 1993 by Christian 'Kochtopf' Scholz"),
  314.                 MD.maApplicationDescription,ADR("a little MUI ComboBox"),
  315.                 MD.maApplicationBase,       ADR("Combo"),
  316.                 MM.SubWindow,               window,
  317.                 tagEnd));
  318.  
  319.     IF app=NIL THEN fail(app,"failed to create application"); END;
  320.  
  321.  (* Notify *)
  322.  
  323.     NoteButton(app, OKBut,     IDOK);
  324.     NoteButton(app, CancelBut, MD.mvApplicationReturnIDQuit);
  325.     NoteClose(app,  window,    MD.mvApplicationReturnIDQuit);
  326.  
  327.  (* the cycle chain *)
  328.     DoMethod(window, TAG(buffer, MD.mmWindowSetCycleChain,
  329.                     String,
  330.                     image,           (* use this and the popup-image
  331.                                         can also be tab-cycled
  332.                                      *)
  333.                     OKBut,
  334.                     CancelBut,
  335.                     NIL));
  336.  
  337.     set(window, MD.maWindowActiveObject, OKBut);
  338.  
  339.  (* Open the window *)
  340.     set(window, MD.maWindowOpen, True);
  341.  
  342.  
  343.  (* MAIN-LOOP *)
  344.  
  345.     WHILE running DO
  346.  
  347.         (* wait for signals IF necessary *)
  348.         IF signals <> LONGSET{} THEN signals:=Wait(signals); END;
  349.  
  350.         (* get the message *)
  351.         msg:=DOMethod(app,TAG(buffer,
  352.                             MD.mmApplicationInput,ADR(signals)));
  353.  
  354.         (* work on message *)
  355.         CASE msg OF
  356.         | MD.mvApplicationReturnIDQuit , IDOK:  (* quit application *)
  357.                 running:=FALSE;
  358.         ELSE
  359.         END; (* CASE *)
  360.  
  361.     END; (* WHILE - Message-LOOP *)
  362.  
  363.     fail(app,"");
  364.  
  365. (******)
  366.  
  367. END ComboBox.
  368.  
  369.  
  370.